package com.dkd.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.dkd.manage.domain.Novel;
import com.dkd.manage.service.INovelService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dkd.common.annotation.Log;
import com.dkd.common.core.controller.BaseController;
import com.dkd.common.core.domain.AjaxResult;
import com.dkd.common.enums.BusinessType;
import com.dkd.manage.domain.NovelTitle;
import com.dkd.manage.service.INovelTitleService;
import com.dkd.common.utils.poi.ExcelUtil;
import com.dkd.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 小说Controller
 * 
 * @author hm
 * @date 2025-03-12
 */
@Api(tags = "小说Controller")
@RestController
@RequestMapping("/manage/novelTitle")
public class NovelTitleController extends BaseController
{
    @Autowired
    private INovelTitleService novelTitleService;

    @Autowired
    private INovelService novelService;

    /**
     * 查询小说列表
     */
    @ApiOperation("查询小说列表")
    @PreAuthorize("@ss.hasPermi('manage:novelTitle:list')")
    @GetMapping("/list")
    public TableDataInfo list(NovelTitle novelTitle)
    {
        startPage();
        List<NovelTitle> list = novelTitleService.selectNovelTitleList(novelTitle);
        return getDataTable(list);
    }

    /**
     * 导出小说列表
     */
    @ApiOperation("导出小说列表")
    @PreAuthorize("@ss.hasPermi('manage:novelTitle:export')")
    @Log(title = "小说", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NovelTitle novelTitle)
    {
        List<NovelTitle> list = novelTitleService.selectNovelTitleList(novelTitle);
        ExcelUtil<NovelTitle> util = new ExcelUtil<NovelTitle>(NovelTitle.class);
        util.exportExcel(response, list, "小说数据");
    }

    /**
     * 获取小说详细信息
     */
    @ApiOperation("获取小说详细信息")
    @PreAuthorize("@ss.hasPermi('manage:novelTitle:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(novelTitleService.selectNovelTitleById(id));
    }

    /**
     * 新增小说
     */
    @ApiOperation("新增小说")
    @PreAuthorize("@ss.hasPermi('manage:novelTitle:add')")
    @Log(title = "小说", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NovelTitle novelTitle)
    {
        return toAjax(novelTitleService.insertNovelTitle(novelTitle));
    }

    /**
     * 修改小说
     */
    @ApiOperation("修改小说")
    @PreAuthorize("@ss.hasPermi('manage:novelTitle:edit')")
    @Log(title = "小说", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NovelTitle novelTitle)
    {
        return toAjax(novelTitleService.updateNovelTitle(novelTitle));
    }

    /**
     * 删除小说
     */
    @ApiOperation("删除小说")
    @PreAuthorize("@ss.hasPermi('manage:novelTitle:remove')")
    @Log(title = "小说", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(novelTitleService.deleteNovelTitleByIds(ids));
    }

    @ApiOperation("获取小说内容")
    @PreAuthorize("@ss.hasPermi('manage:novelTitle:query')")
    @GetMapping("/novelCon/{novelId}")
    public AjaxResult getNovelCon(@PathVariable Long novelId) {
        Novel novel = new Novel();
        novel.setNovelId(novelId);
        List<Novel> novelList = novelService.selectNovelList(novel);
        if (novelList != null && novelList.size() > 0) {
            return success(novelList.get(0).getNovel());
        }
        return error("未找到对应小说内容");
    }

}
